package com.study.springboot.SpringBoot_A.controller;

import com.study.springboot.SpringBoot_A.bean.User;
import com.study.springboot.SpringBoot_A.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.UUID;

/**
 * @author 赵超
 * @Description 第一个SpringBoot程序controller
 * @create 2018-03-21 8:59
 **/
@RestController
public class HelloWorldController {

    @Autowired
    private UserService userService;

    @Value("${indexword}")
    private String world;

    @RequestMapping(value = "/hello")
    public String hello() {
        return world;
    }

    @RequestMapping("/uid")
    public String uid(HttpSession session) {
        UUID uuid = (UUID) session.getAttribute("uid");
        if (uuid == null) {
            uuid = UUID.randomUUID();
        }
        session.setAttribute("uid", uuid);
        return session.getId();
    }

    @RequestMapping("/findByNickNameOrUserName")
    public List<User> findByNickNameOrUserName(String nickName, String userName) {
        return userService.findByNickNameOrUserName(nickName, userName);
    }

    @RequestMapping("getAll")
    public List<User> getAll() {
        return userService.getAll();
    }

    @RequestMapping("addUser")
    public Integer addUser(String userName, String nickName, String passWord) {
        return userService.addUser(userName, nickName, passWord);
    }

}
